package com.gaoxin.api.contronller.stucontroller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.gaoxin.api.entity.statisentity.Course;
import com.gaoxin.api.entity.statisentity.StudentInfo;
import com.gaoxin.api.service.stuservice.QueryAllCourseService;
import com.google.common.collect.Maps;
/**
 * 查询学年学期所有课程
 * @author zhaozhenshe
 *
 */
@RestController
@RequestMapping("app/student")
public class QueryAllCourseController {
	@Autowired
	private QueryAllCourseService queryAllCourseService;
	/**
	 * 查询学年学期所有课程
	 * @return
	 */
	@RequestMapping(value="/queryAllCourse",method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public String queryStudentCourse(@RequestBody Map<String,String> paramMap){
		String [] paramArr = paramMap.get("semester").split("_");
		Map<String, Object> map = Maps.newHashMap();
		String jsonData = null;
		try {
			StudentInfo studentInfo = queryAllCourseService.queryAllCourseByYearAndTerm(paramArr[0], paramArr[1]);
			if(studentInfo!=null){
				map.put("code", "0");
				map.put("results",studentInfo);
				jsonData = JSON.toJSONString(map);
			}else{
				map.put("code", "100104");
				map.put("errmsg", "查询不到该学年学期对应的课程信息！");
				jsonData = JSON.toJSONString(map);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return jsonData;
	}

}
